package com.xdb.sqlparser;

import org.junit.Test;

import com.xdb.sqlparser.ast.SQLStatement;
import com.xdb.sqlparser.ast.statement.SQLSelectItem;
import com.xdb.sqlparser.dialect.oracle.ast.statement.OracleSelectQueryBlock;
import com.xdb.sqlparser.dialect.oracle.parser.OracleStatementParser;
import com.xdb.sqlparser.dialect.oracle.visitor.OracleASTVisitorAdapter;
import com.xdb.sqlparser.dialect.sql99.parser.SQL99StatementParser;

public class MyOracleASTVisitorAdapter extends OracleASTVisitorAdapter {
	@Test
	public void test_1() {
		SQL99StatementParser parser = new OracleStatementParser("select count(1) from table1 t1, (select * from TABLE k) t2 where  t1.name=t2.name(+) group by t1.name");
		SQLStatement st = parser.parseStatement();
		MyOracleASTVisitorAdapter visitor = new MyOracleASTVisitorAdapter();
		st.accept(visitor);
	}

	@Override
	public boolean visit(OracleSelectQueryBlock x) {
		for (SQLSelectItem item : x.getSelectList()) {
			System.out.println(item.getExpr());
			System.out.println(item.getAlias());
		}
		return false;
	}
	@Override
	public void endVisit(OracleSelectQueryBlock x) {
		for (SQLSelectItem item : x.getSelectList()) {
			System.out.println(item.getExpr());
			System.out.println(item.getAlias());
		}
	}

}
